<template>
  <div>
    <div
      class="add"
      v-if="active == 0"
      @click="add()"
    >新增</div>
    <eagle-list
      showTab
      :tabData="tabData"
      @initActive="_initActive"
      @bindData="bindData"
      :filterParams="filterParams"
      :filterParamsDefaul="filterParamsDefaul"
      :filterTab="filterTab"
      allowSearch
      placeholder="请输入文件名称搜索"
      ref="eaglelist"
    >
      <div v-if="this.active === 0">
        <eagle-cell
          style="margin-top: 10px"
          class="card"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="warn_item">
            <div @click="goToDetail(item)">
              <div class="warn_header">
                <div>{{ item.Name }}</div>
              </div>

              <van-row
                gutter="20"
                class="dep_sort"
              >
                <van-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_equ_type.png"
                    alt=""
                    class="icon"
                  />任命书类别：{{ item.AppointmentTypeName }}
                </van-col>
              </van-row>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                    class="icon"
                  />录入人：{{ item.CreateChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                    class="icon"
                  />录入时间：{{ item.CreateDate | formatDateTime }}
                </eagle-col>
              </eagle-row>

              <eagle-file-read-only
                :attachs="item.Attachs"
                :labelName="'签名文件:'"
              ></eagle-file-read-only>
            </div>

            <van-divider />
            <div
              class="dep_btm"
              v-if="item.Status != -1"
            >
              <div
                class="btm_item"
                @click="del(item)"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_abolish.png"
                  alt=""
                  class="icon"
                />
                <div class="mr-10">废止</div>
              </div>
            </div>
            <div
              class="dep_btm"
              v-if="item.Status != -1"
            >
              <div
                class="btm_item"
                @click="goToEdit(item)"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_edit.png"
                  alt=""
                  class="icon"
                />
                <div class="mr-10">编辑</div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </div>
      <div v-if="this.active === 1">
        <eagle-cell
          style="margin-top: 10px"
          class="card"
          v-for="(item, index) in list"
          :key="index"
        >
          <div>
            <div @click="lookPdf(item, '')">
              <eagle-row class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_post.png"
                    alt=""
                    class="icon"
                  />最近修改人：{{ item.EditChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                    class="icon"
                  />最近修改日期：{{ item.EditDate | formatDateTime }}
                </eagle-col>
              </eagle-row>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <div style="display: flex">
                    <div style="width: 80px">签名文件：</div>
                    <div style="flex: 1; overflow: hidden; margin-right: 5px">
                      <div :key="index">
                        <div
                          style="color: #1989fa"
                          @click.stop="lookPdf(item, '')"
                        >
                          {{ item.TemplateName }}
                        </div>
                      </div>
                    </div>
                  </div>
                </eagle-col>
              </eagle-row>
            </div>

            <van-divider />
            <div class="dep_btm">
              <div
                class="btm_item"
                @click.stop="lookPdf(item, '')"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_edit.png"
                  alt=""
                />
                <div class="mr-10">签名</div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      list: [],
      filterTab: true,
      filterParamsDefaul: [{ name: "Status", value: "10" }],
      filterParams: [
        {
          name: "Status",
          title: "状态",
          originTitle: "状态",
          dataType: "int",
          data: [
            { text: "不限", value: "" },
            { text: "现行", value: "10" },
            { text: "废止", value: "-1" },
          ],
        },
        {
          name: "AppointmentType",
          title: "类别",
          originTitle: "类别",
          dataType: "string",
          data: [
            { text: "不限", value: "" },
            { text: "安全生产领导小组认命", value: "A" },
            { text: "安全生产管理人员认命", value: "B" },
          ],
        },
      ],
      tabData: [
        {
          title: "安全管理机构人员任命",
          url: "/SiteAppointment/GetPageData",
          isPage: true,
          params: {
            dataType: "List",
          },
        },
        {
          title: "任命书文件",
          url: "/ProjectEntrustedOnlineDoc/GetPageData",
          isPage: true,
          params: {
            dataType: "List",
            menuNo: "0201",
          },
        },
      ],
      option1: [
        { text: "不限", value: "" },
        { text: "现行", value: "10" },
        { text: "废止", value: "-1" },
      ],
      option2: [
        { text: "不限", value: "" },
        { text: "安全生产领导小组认命", value: "A" },
        { text: "安全生产管理人员认命", value: "B" },
      ],
    };
  },
  methods: {
    goToDetail(item) {
      this.$router.push({
        //name: "SiteappointmentView",
        path: "/SiteappointmentView",
        query: { id: item.ID },
      });
    },
    _initActive(active) {
      if (active === 0) {
        this.$refs.eaglelist.changefilterTab(true);
      }
      if (active === 1) {
        this.$refs.eaglelist.changefilterTab(false);
      }
      this.active = active;
    },
    bindData(data) {
      this.list = data;
    },
    goToEdit(item) {
      this.$router.push({
        path: "/SiteappointmentEdit",
        // name: "SiteappointmentEdit",
        query: { id: item.ID },
      });
    },
    // 新增/编辑
    add() {
      this.$router.push({
        // name: "SiteappointmentAdd",
        path: "/SiteappointmentAdd",
        query: { id: 0 },
      });
    },

    del(item) {
      const _this = this;
      this.$dialog
        .confirm({
          title: "询问",
          message: "您确定废止本条信息吗？",
        })
        .then(() => {
          this.$axios
            .get("/SiteAppointment/Abolish", { params: { id: item.ID } })
            .then((res) => {
              _this.$toast.success("废止成功！");
              setTimeout(() => {
                _this.$refs.eaglelist.getList();
              }, 300);
            })
            .catch((err) => {
              console.log("err", err);
            });
        })
        .catch(() => {
          // on cancel
        });
    },

    // 附件详情
    goFile(attachCode) {
      this.$router.push("/Attach/AatachDetail?attCode=" + attachCode);
    },

    // 查看报告
    lookPdf(item, ids) {
      this.$router.push({
        name: "CheckReportDetail2",
        query: {
          url: process.env.VUE_APP_BASE_API + item.PdfAttach,
          TypeName: this.titleCode,
          isSignature: "ProjectEntrustedOnlineDoc",
          IDS: ids,
          DocCode: item.Code,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}

.warn_item {
  /*margin-bottom: 10px;*/
  // padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: 0;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  width: 30%;
  float: right;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
